package com.tt.dao;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;
import com.tt.entity.Food;
import com.tt.entity.ListImg;

@Repository

public class FoodDaoImpl {
	@Resource
	private SessionFactory sessionFactory;
	
	//��ѯ������ʳ��Ϣ
   public List<Food> foodfoundAll(){
   String hql ="from Food";
   Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
   List<Food> Flist = query.list();
   return Flist;
}
   
   //�����ʳ
   
   public int addFood(Food food){
	   
	  int addFood=(int) this.sessionFactory.getCurrentSession().save(food);
      System.out.println(food);
	  return 1 ;
   }
   
   //ɾ��
   public void  deteleFood(Integer id){
	   
/*	   String hql=" detele from Food where id=?";
	   Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0,id);
		int result=query.executeUpdate();

	  	   
		if(result>0){
		return true;
		}else{
		Food detefood=(Food) query.uniqueResult();
		return false;
		}*/  
	   Session session = this.sessionFactory.getCurrentSession();
	   Food food = session.get(Food.class, id);
	   session.delete(food);
	
   }	
		   


   
   //�޸�
   public  void  updateFood(Food food){
	   this.sessionFactory.getCurrentSession().update(food);
   }
   
   //ͼƬ�޸�
	public String  updatephoto(Integer id){
		Query query=this.sessionFactory.getCurrentSession().createQuery("select img from Food where id=?");
		query.setParameter(0, id);
		String listimg = (String) query.uniqueResult();
		return listimg;
	}
   
   //id ����
   public Food showFood(Integer id){
	   String hql ="from Food where id=?";
	   Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
	   query.setParameter(0, id);
	   Food fid = (Food) query.uniqueResult();
	   return fid;
	   
   }
   //foodsingle
   public Food showFoodsingle(Integer id){
	   String hql ="from Food where id=?";
	   Query query = this.sessionFactory.getCurrentSession().createQuery(hql);
	   query.setParameter(0, id);
	   Food fid = (Food) query.uniqueResult();
	   return fid;
   }
}
